﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AddressBook.DAO;
using AddressBook.Entity;
using System.Text;

public partial class GetNotifyInfo : System.Web.UI.Page
{
    static NoticesDAO dao = new NoticesDAO();

    protected void Page_Load(object sender, EventArgs e)
    {
        ResultEntity result = new ResultEntity();
        result.Name = "NotifyInfo";

        if (!string.IsNullOrEmpty(Request.QueryString["NoticeID"]))
        {
            Guid id;
            if (Guid.TryParse(Request.QueryString["NoticeID"], out id))
            {
                Notices noti = dao.GetInfoByKey(id);

                if (noti != null)
                {
                    result.ResultCode = "0";
                    StringBuilder sb = new StringBuilder();
                    sb.Append("{");
                    sb.AppendFormat("\"Title\":\"{0}\",", noti.Title.Replace("\"", ""));
                    sb.AppendFormat("\"NoticeID\":\"{0}\",", noti.NoticeID.ToString());   
                    sb.AppendFormat("\"Contents\":\"{0}\",", noti.Contents.Replace("\"", ""));
                    sb.AppendFormat("\"PublishDeptID\":\"{0}\",", noti.PublishDeptID);                    
                    sb.AppendFormat("\"PublishUserID\":\"{0}\",", noti.PublishUserID);                    
                    sb.AppendFormat("\"PublishTime\":\"{0}\"", noti.PublishTime);
                    sb.Append("}");

                    result.Contents = sb.ToString();
                }
                else
                {
                    result.Desc = "该公告不存在或者已被删除！";
                    result.ResultCode = "-1";
                }
            }
            else
            {
                result.Desc = "参数不正确！";
                result.ResultCode = "-2";
            }
        }
        else
        {
            result.Desc = "参数不正确！";
            result.ResultCode = "-2";
        }

        Response.Write(Common.ReturnResult(result));
    }
}